# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=pyqt6
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.2.1
pkgrel=1
pkgdesc="Python bindings for the Qt cross platform application toolkit (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL')
url="https://riverbankcomputing.com/software/pyqt"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyqt6-sip"
         "${MINGW_PACKAGE_PREFIX}-qt6-base")
optdepends=("${MINGW_PACKAGE_PREFIX}-qt6-tools"
            "${MINGW_PACKAGE_PREFIX}-qt6-svg"
            "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
            "${MINGW_PACKAGE_PREFIX}-qt6-quick3d"
            "${MINGW_PACKAGE_PREFIX}-qt6-shadertools"
            "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
            "${MINGW_PACKAGE_PREFIX}-qt6-remoteobjects"
            "${MINGW_PACKAGE_PREFIX}-qt6-location"
            "${MINGW_PACKAGE_PREFIX}-qt6-sensors"
            "${MINGW_PACKAGE_PREFIX}-qt6-serialport"
            "${MINGW_PACKAGE_PREFIX}-qt6-webchannel"
            "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
            "${MINGW_PACKAGE_PREFIX}-qt6-connectivity"
            "${MINGW_PACKAGE_PREFIX}-qt6-activeqt")
makedepends=("${MINGW_PACKAGE_PREFIX}-sip"
             "${MINGW_PACKAGE_PREFIX}-pyqt-builder"
             "${MINGW_PACKAGE_PREFIX}-python-packaging"
             "${MINGW_PACKAGE_PREFIX}-qt6-tools"
             "${MINGW_PACKAGE_PREFIX}-qt6-svg"
             "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
             "${MINGW_PACKAGE_PREFIX}-qt6-quick3d"
             "${MINGW_PACKAGE_PREFIX}-qt6-shadertools"
             "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
             "${MINGW_PACKAGE_PREFIX}-qt6-remoteobjects"
             "${MINGW_PACKAGE_PREFIX}-qt6-location"
             "${MINGW_PACKAGE_PREFIX}-qt6-sensors"
             "${MINGW_PACKAGE_PREFIX}-qt6-serialport"
             "${MINGW_PACKAGE_PREFIX}-qt6-webchannel"
             "${MINGW_PACKAGE_PREFIX}-qt6-websockets"
             "${MINGW_PACKAGE_PREFIX}-qt6-connectivity"
             "${MINGW_PACKAGE_PREFIX}-qt6-activeqt"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://pypi.python.org/packages/source/P/PyQt6/PyQt6-${pkgver}.tar.gz
        "001-fix-undefined-reference-stat.patch")
sha256sums=('d603a5c8effccc9174b3f43834256401a61ea40f2338306ca22fb6a1e870b89c'
            '37f2326c97b5ebaa1a3a8e8e3349eed6baf4ee968296827e0e12f90263aa38a3')

prepare() {
  cd PyQt6-${pkgver}

  patch -p1 -i ${srcdir}/001-fix-undefined-reference-stat.patch
}

build() {
  [[ -d python-${MSYSTEM} ]] && rm -rf python-${MSYSTEM}
  cp -r PyQt6-${pkgver} python-${MSYSTEM} && cd python-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--api-dir=;" \
  ${MINGW_PREFIX}/bin/sip-build \
    --confirm-license \
    --no-make \
    --api-dir=${MINGW_PREFIX}/share/qt6/qsci/api/python \
    --qmake=${MINGW_PREFIX}/bin/qmake6.exe \
    --concatenate 2 \
    --verbose

    cd build
    make V=1
}

package(){
  local _pysite=$(cygpath -u $(${MINGW_PREFIX}/bin/python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"))
  cd python-${MSYSTEM}/build
  # INSTALL_ROOT is needed for the QtDesigner module, the other Makefiles use DESTDIR
  MSYS2_ARG_CONV_EXCL="${_pysite}" \
  make DESTDIR="${pkgdir}" INSTALL_ROOT="${pkgdir}" install

  # compile Python bytecode
  ${MINGW_PREFIX}/bin/python -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
  ${MINGW_PREFIX}/bin/python -O -m compileall -d / "$pkgdir"${MINGW_PREFIX}/lib
}
